<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-7-29
 * Time: 上午9:41
 */

namespace common\models\db;

/**
 * Class Role
 * @package common\models\db
 *
 * @property User $createdBy
 * @property RoleAction[] $roleActions
 * @property Action[] $actions
 * @property RoleMenu[] $roleMenus
 * @property Menu[] $menus
 * @property RoleUser[] $roleUsers
 * @property User[] $users
 */
class Role extends \common\models\db\tables\Role
{
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoleActions()
    {
        return $this->hasMany(RoleAction::className(), ['role_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getActions()
    {
        return $this->hasMany(Action::className(), ['id' => 'action_id'])->viaTable('{{%role_action}}', ['role_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoleMenus()
    {
        return $this->hasMany(RoleMenu::className(), ['role_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMenus()
    {
        return $this->hasMany(Menu::className(), ['id' => 'menu_id'])->viaTable('{{%role_menu}}', ['role_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoleUsers()
    {
        return $this->hasMany(RoleUser::className(), ['role_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsers()
    {
        return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('{{%role_user}}', ['role_id' => 'id']);
    }
}